package com.community.controller;

import com.community.dto.StorageGatherDto;
import com.community.pojo.Orders;
import com.community.pojo.Product;
import com.community.service.IOrdersService;
import com.community.utils.NumberUtils;
import com.community.utils.PageUtils;
import com.community.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TangHaoSong Fly ChenJie HeYuHang
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/community/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @Autowired
    private NumberUtils numberUtils;

    @RequestMapping("/add")
    @ResponseBody
    public String add(@RequestBody Orders orders) {
        System.out.println("orders++++"+orders);
        //为结算购物车生成订单
        Orders orders1 = new Orders();
        orders1.setOrderId(null);
        String typeNumber = numberUtils.getTypeNumber("300");
        orders1.setOrderNumber(typeNumber);
        orders.setConsumerId(1);
        //创建时间
        orders1.setCreatedTime(new Date());
        //支付方式，P002-1（余额支付）、P002-2（微信支付）、P003（现金支付）
        orders1.setPayMethod("P002-2");
        //配送标志，P001-1（待发货）、P001-2（待收货）、P001-3（已收货）
        orders1.setConveyTag("P001-1");
        //支付标志，K002-1（等待支付）、K002-2（支付失败）、K002-3（支付成功）
        orders1.setPayTag("K002-1");
        orders1.setTotalAmount(orders.getTotalAmount());
        orders1.setTotalPrice(orders.getTotalPrice());
        ordersService.save(orders1);
        return "ok";
    }
}
